//恭喜发财，利是窦来

#include <stdio.h>
#include <string.h>

void calculate( int money , char *name , char (*allname)[15] , int (*result)[1] , int numofpeople );
void clear( char *a );

int main()
{
	char store[100][15]={'\0'};
	int allmoney=0;
	int numofpeople=0;
	int result[15][1]={0};
	char compare[15]={'\0'};
	int money=0;
	int divide=-1;
	
	//基础输入部分
	scanf("%d",&numofpeople);
	for ( int i=0 ; i<=numofpeople ; i++ )
	{
		gets(store[i-1]);
	}
	
	//每次输入并计算
	for ( int i=0 ; i<=numofpeople ; i++ )
	{
		//输入部分
		gets(compare);
		scanf("%d %d",&allmoney,&divide);
		divide = divide;
		if ( divide == 0 )
		{
			clear( compare );
			allmoney=0;
			divide=0;
			money=0;
			continue;
		}
		money = allmoney / divide ;
		
		//计算部分
		calculate ( -divide*money , compare , store , result , numofpeople );
		clear( compare );
		getchar();
		for ( int j=0 ; j<divide ; j++ )
		{
			gets(compare);
			calculate( money , compare , store , result , numofpeople );
			clear( compare );
		}
		
		//清零部分
		clear( compare );
		allmoney=0;
		divide=-1;
		money=0;
	}
	
	//输出部分
	for ( int k=0 ; k<numofpeople ; k++ )
	{
		printf("%s ", store[k] );
		printf("%d\n", result[k][0] );
	}
	
	return 0;
}


void calculate( int money , char *name , char (*allname)[15] , int (*result)[1] , int numofpeople )
{
	for ( int i=0 ; i<numofpeople ; i++ )
	{
		if ( strcmp ( name , *(allname+i) ) == 0 )
		{
			result[i][0] = result[i][0] + money;
		}
	}
}

void clear( char *a )
{
	int length=0;
	length = strlen(a);
	for ( int i=0 ; i<length ; i++ )
	{
		a[i] = '\0';
	}
}

